package com.order.controller;

import cloud.api.pojo.Payment;
import cloud.api.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author zw
 * @date 2022-08-20.
 */
@RestController
@RequestMapping("consumer")
@Slf4j
public class OrderController {
    public final static String PAY_URL = "http://PAY-SERVICE/";
    @Resource
    private RestTemplate restTemplate;

    @PostMapping("Payment/create")
    public Result create(@RequestBody Payment payment){
        String url = PAY_URL + "Payment/insert";
        log.info("发送请求为 : " + url);
        log.info("数据为 : " + payment.toString());
        return restTemplate.postForObject(url,payment,Result.class);
    }
    @GetMapping("Payment/getPaymentById/{id}")
    public Result getPaymentById(@PathVariable Long id){
        String url = PAY_URL + "Payment/getPaymentById/"+id;
        log.info("发送请求为 : " + url);
        log.info("数据为 : " + id);
        return restTemplate.getForObject(url,Result.class);
    }
}